from typing import List


class Solution:
    def getMaximumXor(self, nums: List[int], max_bit: int) -> List[int]:
        size = len(nums)

        xor = 0
        for num in nums:
            xor ^= num

        v = 2 ** max_bit - 1

        ans = []
        for i in range(size - 1, -1, -1):
            ans.append((xor & v) ^ v)
            xor ^= nums[i]
        return ans


if __name__ == "__main__":
    # [0,3,2,3]
    print(Solution().getMaximumXor(nums=[0, 1, 1, 3], max_bit=2))

    # [5,2,6,5]
    print(Solution().getMaximumXor(nums=[2, 3, 4, 7], max_bit=3))

    # [4,3,6,4,6,7]
    print(Solution().getMaximumXor(nums=[0, 1, 2, 2, 5, 7], max_bit=3))
